﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Com.CMS263.BLL;

namespace Com.CMS263.Web.manage
{
    public partial class manageClass : System.Web.UI.Page
    {
        int pageSize = 15;
        ClassesBLL bll = new ClassesBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            int page = string.IsNullOrEmpty(Request["page"])?1:int.Parse(Request["page"]);
            this.BindData(page);
        }

        private void BindData(int page)
        {
            this.GridView1.DataSource = bll.GetClasses(page, pageSize);
            this.GridView1.DataBind();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName.Equals("btnDel"))
            {
                try
                {
                    bll.Delete(id);
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "js", "alert('删除成功')", true);
                }
                catch
                {

                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "js", "alert('删除失败')", true);
                }

                BindData(1);
            }
            else if (e.CommandName.Equals("btnEdit"))
            {
                Response.Redirect("addClass.aspx");
            }
        }
        public string GetPager()
        {
            return "";
        }
       
    }
}
